package org.dromara.administration.service.impl;

import org.dromara.administration.domain.bo.AdmSealAuditBo;
import org.dromara.administration.domain.vo.AdmSealIdeaVo;
import org.dromara.common.core.constant.AdministrationConstants;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.dromara.administration.domain.bo.AdmSealBo;
import org.dromara.administration.domain.vo.AdmSealVo;
import org.dromara.administration.domain.AdmSeal;
import org.dromara.administration.domain.AdmSealFile;
import org.dromara.administration.domain.AdmApplyRelation;
import org.dromara.administration.domain.base.AdmSealBaseEntity;
import org.dromara.administration.domain.bo.AdmSealSaveBo;
import org.dromara.administration.domain.bo.AdmSealFileBo;
import org.dromara.administration.mapper.AdmSealMapper;
import org.dromara.administration.mapper.AdmSealFileMapper;
import org.dromara.administration.mapper.AdmApplyRelationMapper;
import org.dromara.administration.service.IAdmSealService;
import org.dromara.common.core.constant.AdministrationConstants.SealApprovalStatus;
import org.dromara.common.core.constant.AdministrationConstants.SealApplyRelationStatus;
import org.dromara.system.service.ISysUserService;
import org.dromara.administration.domain.vo.AdmSealAuditVo;
import org.dromara.system.service.ISysDeptService;
import org.dromara.common.core.exception.ServiceException;

import java.util.List;
import java.util.Collection;
import java.time.LocalDate;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.Map;

/**
 * 公章管理Service业务层处理
 *
 * @author LUSH
 * @date 2025-05-20
 */
@RequiredArgsConstructor
@Service
public class AdmSealServiceImpl implements IAdmSealService {

    private final AdmSealMapper baseMapper;
    private final AdmSealFileMapper admSealFileMapper;
    private final AdmApplyRelationMapper admApplyRelationMapper;
    private final ISysUserService userService;
    private final ISysDeptService deptService;

    /**
     * 分页查询公章管理列表
     */
    @Override
    public TableDataInfo<AdmSealVo> queryPageList(AdmSealBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<AdmSeal> lqw = buildPageQueryWrapper(bo);
        Long userId = LoginHelper.getUserId();
        buildPermissionQueryWrapper(lqw, userId);
        Page<AdmSealVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 构建权限查询条件
     * 根据用户权限构建不同的查询条件：
     * 1. 最终审核人可以看到所有待审核的公章申请和自己申请的公章
     * 2. 普通用户只能看到与自己相关的公章申请
     *
     * @param lqw 查询条件构建器
     * @param userId 当前用户ID
     */
    private void buildPermissionQueryWrapper(LambdaQueryWrapper<AdmSeal> lqw, Long userId) {
        // 判断用户是否有最终审核权限
        boolean hasFinalApprover = userService.isFinalApprover();

        if (hasFinalApprover) {
            // 如果有最终审核权限，返回状态为1、2、3、4的公章申请列表
            lqw.in(AdmSeal::getStatus, List.of(
                SealApprovalStatus.PRINCIPAL_APPROVED,
                SealApprovalStatus.APPROVER_APPROVED,
                SealApprovalStatus.APPROVER_REJECTED
            ));

            // 获取当前用户作为申请人的公章ID列表
            List<Long> selfApplySealIds = admApplyRelationMapper.selectSealIdsByApplicantId(userId);
            if (selfApplySealIds != null && !selfApplySealIds.isEmpty()) {
                // 使用or条件，包含自己申请的公章
                lqw.or(w -> w.in(AdmSeal::getId, selfApplySealIds));
            }
        } else {
            // 否则只返回当前用户相关的公章
            List<Long> applySealIds = admApplyRelationMapper.selectSealIdsByApplicantId(userId);
            List<Long> principalSealIds = admApplyRelationMapper.selectSealIdsByPrincipalId(userId);
            Set<Long> allSealIds = new HashSet<>();
            if (applySealIds != null) allSealIds.addAll(applySealIds);
            if (principalSealIds != null) allSealIds.addAll(principalSealIds);
            if (!allSealIds.isEmpty()) {
                lqw.in(AdmSeal::getId, allSealIds);
            } else {
                lqw.apply("1=0"); // 如果没有相关公章，返回空结果
            }
        }
    }

    /**
     * 分页查询条件封装，仅保留页面展示的筛选项
     */
    private LambdaQueryWrapper<AdmSeal> buildPageQueryWrapper(AdmSealBo bo) {
        LambdaQueryWrapper<AdmSeal> lqw = Wrappers.lambdaQuery();
        Map<String, Object> params = bo.getParams();

        lqw.eq(StringUtils.isNotBlank(bo.getNumber()), AdmSeal::getNumber, bo.getNumber())
           .eq(bo.getUseDate() != null, AdmSeal::getUseDate, bo.getUseDate())
           .eq(StringUtils.isNotBlank(bo.getUseType()), AdmSeal::getUseType, bo.getUseType())
           .eq(StringUtils.isNotBlank(bo.getStatus()), AdmSeal::getStatus, bo.getStatus())
           // 处理创建时间范围
           .between(params.get("beginTime") != null && params.get("endTime") != null,
               AdmSeal::getCreateTime, params.get("beginTime"), params.get("endTime"))
           // 处理使用时间范围
           .between(params.get("bUseTime") != null && params.get("eUseTime") != null,
               AdmSeal::getUseDate, params.get("bUseTime"), params.get("eUseTime"))
           .orderByDesc(AdmSeal::getCreateTime);

        return lqw;
    }

    /**
     * 查询符合条件的公章管理列表
     *
     * @param bo 查询条件
     * @return 公章管理列表
     */
    @Override
    public List<AdmSealVo> queryList(AdmSealBo bo) {
        LambdaQueryWrapper<AdmSeal> lqw = buildPageQueryWrapper(bo);
        Long userId = LoginHelper.getUserId();
        buildPermissionQueryWrapper(lqw, userId);
        return baseMapper.selectVoList(lqw);
    }

    /**
     * 新增公章管理
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertByBo(AdmSealSaveBo bo) {
        // 1. 保存AdmSeal
        AdmSeal add = buildSealEntity(bo);
        boolean flag = baseMapper.insert(add) > 0;
        if (!flag) {
            throw new ServiceException("保存公章申请失败");
        }
        Long sealId = add.getId();

        // 2. 保存AdmSealFile
        if (bo.getSealFiles() != null && !bo.getSealFiles().isEmpty()) {
            for (AdmSealFileBo fileBo : bo.getSealFiles()) {
                AdmSealFile file = buildSealFileEntity(fileBo, sealId);
                boolean fileFlag = admSealFileMapper.insert(file) > 0;
                if (!fileFlag) {
                    throw new ServiceException("保存公章文件失败");
                }
            }
        }

        // 3. 保存公章与审核人员的关系
        if (StringUtils.isNotBlank(bo.getPrincipalIds())) {
            String[] principalIdArray = bo.getPrincipalIds().split(",");
            for (String principalIdStr : principalIdArray) {
                Long principalId = Long.parseLong(principalIdStr.trim());
                AdmApplyRelation relation = new AdmApplyRelation();
                relation.setSealId(sealId);
                relation.setPrincipalId(principalId);
                relation.setApplicantId(LoginHelper.getUserId());
                relation.setStatus(SealApplyRelationStatus.PENDING); // 设置初始状态为未审批
                boolean relationFlag = admApplyRelationMapper.insert(relation) > 0;
                if (!relationFlag) {
                    throw new ServiceException("保存审核关系失败");
                }
            }
        }

        return true;
    }

    /**
     * 权限校验：验证用户是否有权限操作指定的公章申请
     * @param sealId 公章申请ID
     */
    private void validateSealPermission(Long sealId) {
        Long userId = LoginHelper.getUserId();
        AdmSeal seal = baseMapper.selectById(sealId);
        if (seal == null) {
            throw new ServiceException("公章申请不存在");
        }
        if (!userId.equals(seal.getApplyId())) {
            throw new ServiceException("无权操作：只能操作自己申请的公章");
        }
    }

    /**
     * 权限校验：验证用户是否有权限操作指定的公章申请，并检查状态是否允许修改
     * @param sealId 公章申请ID
     */
    private void validateSealEditPermission(Long sealId) {
        validateSealPermission(sealId);
        AdmSeal seal = baseMapper.selectById(sealId);
        String status = seal.getStatus();
        if (!SealApprovalStatus.PENDING.equals(status)
                && !SealApprovalStatus.PRINCIPAL_REJECTED.equals(status)
                && !SealApprovalStatus.APPROVER_REJECTED.equals(status)) {
            throw new ServiceException("当前状态不允许修改");
        }
    }

    /**
     * 权限校验：验证用户是否有权限删除指定的公章申请
     * @param ids 公章申请ID集合
     */
    private void validateSealDeletePermission(Collection<Long> ids) {
        Long userId = LoginHelper.getUserId();
        List<AdmSeal> seals = baseMapper.selectBatchIds(ids);
        if (seals.size() != ids.size()) {
            throw new ServiceException("部分公章申请不存在");
        }
        boolean allMatch = seals.stream().allMatch(seal -> userId.equals(seal.getApplyId()));
        if (!allMatch) {
            throw new ServiceException("无权删除：只能删除自己申请的公章");
        }
        // 增加判断：只有当前申请为未审批状态才能删除
        boolean allPending = seals.stream().allMatch(seal -> SealApprovalStatus.PENDING.equals(seal.getStatus()));
        if (!allPending) {
            throw new ServiceException("只能删除未审批状态的公章申请");
        }
    }

    /**
     * 修改公章管理
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByBo(AdmSealSaveBo bo) {
        if (bo.getId() == null) {
            throw new ServiceException("公章申请ID不能为空");
        }
        // 权限校验
        validateSealEditPermission(bo.getId());

        // 1. 更新主表
        AdmSeal update = buildSealEntity(bo);
        update.setId(bo.getId());
        boolean flag = baseMapper.updateById(update) > 0;
        if (!flag) {
            throw new ServiceException("更新公章申请失败");
        }
        // 2. 文件和关系表处理
        try {
            insertOrUpdateFilesAndRelations(bo.getId(), bo, bo.getApplyId());
        } catch (Exception e) {
            throw new ServiceException("更新公章文件和审核关系失败");
        }
        return true;
    }

    /**
     * 删除公章管理
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteWithValidByIds(Collection<Long> ids) {
        // 权限校验
        validateSealDeletePermission(ids);

        // 1. 删除公章申请相关的文件表信息
        for (Long id : ids) {
            int fileDeleted = admSealFileMapper.deletePhysicalBySealId(id);
            // 允许没有文件的情况，所以不检查删除数量
        }

        // 2. 删除sealId对应的关系表信息
        for (Long id : ids) {
            int relationDeleted = admApplyRelationMapper.deletePhysicalBySealId(id);
            // 允许没有关系的情况，所以不检查删除数量
        }

        // 3. 删除申请表信息
        boolean sealDeleted = baseMapper.deleteByIds(ids) > 0;
        if (!sealDeleted) {
            throw new ServiceException("删除公章申请失败");
        }

        return true;
    }

    @Override
    public String generateNextSealNumber() {
        LocalDate today = LocalDate.now();
        String year = String.valueOf(today.getYear());
        String month = String.format("%02d", today.getMonthValue());
        String day = String.format("%02d", today.getDayOfMonth());

        // 统计今年的数量
        LocalDate startOfYear = today.withDayOfYear(1);
        LocalDate endOfYear = today.withMonth(12).withDayOfMonth(31);
        LambdaQueryWrapper<AdmSeal> lqw = Wrappers.lambdaQuery();
        lqw.ge(AdmSeal::getUseDate, startOfYear);
        lqw.le(AdmSeal::getUseDate, endOfYear);
        long count = baseMapper.selectCount(lqw);
        String countStr = String.format("%03d", count + 1);
        return "SEAL" + year + countStr + month + day;
    }

    /**
     * 获取公章申请详细信息
     */
    @Override
    public AdmSealSaveBo getEditInfoById(Long id) {
        AdmSealSaveBo bo = buildSealVo(id, AdmSealSaveBo.class);
        if (bo == null) {
            throw new ServiceException("公章申请不存在");
        }
        return bo;
    }

    /**
     * 获取公章申请审核详情
     */
    @Override
    public AdmSealAuditVo getAuditInfoById(Long id, String auditType) {
        AdmSealAuditVo vo = buildSealVo(id, AdmSealAuditVo.class);
        if (vo == null) {
            throw new ServiceException("公章申请不存在");
        }
        if (AdministrationConstants.AuditType.CEO.equals(auditType)) {
            // 查询所有部门审核人及意见
            List<AdmApplyRelation> relations = admApplyRelationMapper.selectList(
                Wrappers.<AdmApplyRelation>lambdaQuery().eq(AdmApplyRelation::getSealId, id)
            );
            List<AdmSealIdeaVo> deptIdeas = relations.stream().map(r -> {
                AdmSealIdeaVo ideaVo = new AdmSealIdeaVo();
                var user = userService.selectUserById(r.getPrincipalId());
                ideaVo.setPrincipalName(user != null ? user.getNickName() : "");
                ideaVo.setPrincipalIdea(r.getPrincipalIdea());
                return ideaVo;
            }).collect(java.util.stream.Collectors.toList());
            vo.setDeptIdeas(deptIdeas);
        } else if (AdministrationConstants.AuditType.DEPT.equals(auditType)) {
            // 查询当前审核员的审核意见
            Long principalId = LoginHelper.getUserId();
            AdmApplyRelation relation = admApplyRelationMapper.selectOne(
                Wrappers.<AdmApplyRelation>lambdaQuery()
                    .eq(AdmApplyRelation::getSealId, id)
                    .eq(AdmApplyRelation::getPrincipalId, principalId)
            );
            if (relation != null) {
                vo.setPrincipalIdea(relation.getPrincipalIdea());
            }
        }
        return vo;
    }

    /**
     * 公章审核
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean auditSeal(AdmSealAuditBo bo) {
        // 董办审核，直接更新主表
        if (AdministrationConstants.AuditType.CEO.equals(bo.getAuditType())) {
            AdmSeal seal = baseMapper.selectById(bo.getId());
            if (seal == null) {
                throw new ServiceException("公章申请不存在");
            }
            // 只更新主表状态和董办意见
            seal.setStatus(bo.getStatus());
            seal.setApproverIdea(bo.getPrincipalIdea());
            boolean updated = baseMapper.updateById(seal) > 0;
            if (!updated) {
                throw new ServiceException("董办审核失败");
            }
            return true;
        }

        // 部门审核，更新印章关系表
        if (AdministrationConstants.AuditType.DEPT.equals(bo.getAuditType())) {
            bo.setPrincipalId(LoginHelper.getUserId());
            List<AdmApplyRelation> relations = admApplyRelationMapper.selectList(
                Wrappers.<AdmApplyRelation>lambdaQuery()
                    .eq(AdmApplyRelation::getSealId, bo.getId())
            );
            if (relations.isEmpty()) {
                throw new ServiceException("未找到审核关系信息");
            }

            // 更新当前审核人的关系状态
            boolean updated = admApplyRelationMapper.update(null,
                Wrappers.<AdmApplyRelation>lambdaUpdate()
                    .eq(AdmApplyRelation::getSealId, bo.getId())
                    .eq(AdmApplyRelation::getPrincipalId, bo.getPrincipalId())
                    .set(AdmApplyRelation::getStatus, bo.getStatus()
                        .equals(SealApprovalStatus.PRINCIPAL_REJECTED) ? SealApplyRelationStatus.REJECTED : bo.getStatus())
                    .set(AdmApplyRelation::getPrincipalIdea, bo.getPrincipalIdea())
            ) > 0;

            if (!updated) {
                throw new ServiceException("更新审核关系失败");
            }

            // 手动更新relations中当前用户的状态，确保状态判定准确
            for (AdmApplyRelation relation : relations) {
                if (relation.getPrincipalId().equals(bo.getPrincipalId())) {
                    relation.setStatus(bo.getStatus().equals(SealApprovalStatus.PRINCIPAL_REJECTED) ? SealApplyRelationStatus.REJECTED : bo.getStatus());
                    break;
                }
            }

            // 判断是否只有一个负责人
            if (relations.size() == 1) {
                boolean success = baseMapper.update(null,
                    Wrappers.<AdmSeal>lambdaUpdate()
                        .eq(AdmSeal::getId, bo.getId())
                        .set(AdmSeal::getStatus, bo.getStatus())
                ) > 0;

                if (!success) {
                    throw new ServiceException("更新公章状态失败");
                }
                return true;
            }

            // 多个负责人的情况
            String newStatus = getNewStatus(relations);

            boolean success = baseMapper.update(null,
                Wrappers.<AdmSeal>lambdaUpdate()
                    .eq(AdmSeal::getId, bo.getId())
                    .set(AdmSeal::getStatus, newStatus)
            ) > 0;

            if (!success) {
                throw new ServiceException("更新公章状态失败");
            }
            return true;
        }

        throw new ServiceException("无效的审核类型");
    }

    @NotNull
    private static String getNewStatus(List<AdmApplyRelation> relations) {
        boolean allApproved = true;
        boolean hasRejected = false;
        boolean hasPending = false;

        for (AdmApplyRelation relation : relations) {
            if (SealApplyRelationStatus.PENDING.equals(relation.getStatus())) {
                hasPending = true;
                allApproved = false;
            } else if (SealApplyRelationStatus.APPROVED.equals(relation.getStatus())) {
                // 已审核通过，继续检查
            } else if (SealApplyRelationStatus.REJECTED.equals(relation.getStatus())) {
                hasRejected = true;
                allApproved = false;
            }
        }

        // 根据审核情况更新状态
        String newStatus;
        if (hasRejected) {
            newStatus = SealApprovalStatus.PRINCIPAL_REJECTED;
        } else if (hasPending) {
            newStatus = SealApprovalStatus.PRINCIPAL_REVIEWING;
        } else if (allApproved) {
            newStatus = SealApprovalStatus.PRINCIPAL_APPROVED;
        } else {
            throw new ServiceException("审核状态异常");
        }
        return newStatus;
    }

    /**
     * 构建印章实体
     *
     * @param bo 印章保存业务对象
     * @return 印章实体
     */
    private AdmSeal buildSealEntity(AdmSealSaveBo bo) {
        AdmSeal add = new AdmSeal();
        add.setNumber(bo.getNumber());
        add.setDeptId(bo.getDeptId());
        add.setUseDate(bo.getUseDate());
        add.setUseType(String.valueOf(bo.getUseType()));
        add.setSealType(bo.getSealType());
        add.setStatus(bo.getStatus());
        add.setSealCause(bo.getSealCause());
        add.setApplyId(LoginHelper.getUserId());
        add.setRemark(bo.getRemark());
        return add;
    }

    /**
     * 构建印章文件实体
     *
     * @param fileBo 印章文件业务对象
     * @param sealId 印章ID
     * @return 印章文件实体
     */
    private AdmSealFile buildSealFileEntity(AdmSealFileBo fileBo, Long sealId) {
        AdmSealFile file = MapstructUtils.convert(fileBo, AdmSealFile.class);
        file.setSealId(sealId);
        file.setFileName(fileBo.getFileName());
        file.setFileCount(fileBo.getFileCount());
        file.setCreateTime(new Date());
        return file;
    }

    /**
     * 新增或更新公章文件和审核关系表（先删后增）
     */
    private void insertOrUpdateFilesAndRelations(Long sealId, AdmSealSaveBo bo, Long applicantId) {
        // 1. 先删除原有文件
        admSealFileMapper.delete(Wrappers.<AdmSealFile>lambdaQuery().eq(AdmSealFile::getSealId, sealId));
        // 2. 重新插入文件
        if (bo.getSealFiles() != null && !bo.getSealFiles().isEmpty()) {
            for (AdmSealFileBo fileBo : bo.getSealFiles()) {
                AdmSealFile file = buildSealFileEntity(fileBo, sealId);
                admSealFileMapper.insert(file);
            }
        }
        // 3. 删除原有审核关系
        admApplyRelationMapper.delete(Wrappers.<AdmApplyRelation>lambdaQuery().eq(AdmApplyRelation::getSealId, sealId));
        // 4. 重新插入审核关系
        if (StringUtils.isNotBlank(bo.getPrincipalIds())) {
            String[] principalIdArray = bo.getPrincipalIds().split(",");
            for (String principalIdStr : principalIdArray) {
                Long principalId = Long.parseLong(principalIdStr.trim());
                AdmApplyRelation relation = new AdmApplyRelation();
                relation.setSealId(sealId);
                relation.setPrincipalId(principalId);
                relation.setApplicantId(applicantId);
                relation.setStatus(SealApplyRelationStatus.PENDING); // 设置初始状态为未审批
                admApplyRelationMapper.insert(relation);
            }
        }
    }

    /**
     * 组装公章申请基础信息（泛型方法，统一处理）
     */
    private <T extends AdmSealBaseEntity> T buildSealVo(Long id, Class<T> targetClass) {
        AdmSeal seal = baseMapper.selectById(id);
        if (seal == null) return null;

        try {
            T entity = targetClass.getDeclaredConstructor().newInstance();
            // 设置基础字段
            entity.setId(seal.getId());
            entity.setNumber(seal.getNumber());
            entity.setDeptId(seal.getDeptId());
            entity.setUseDate(seal.getUseDate());
            entity.setUseType(seal.getUseType() != null ? seal.getUseType().charAt(0) : null);
            entity.setSealType(seal.getSealType());
            entity.setStatus(seal.getStatus());
            entity.setRemark(seal.getRemark());
            entity.setSealCause(seal.getSealCause());
            entity.setApplyId(seal.getApplyId());

            // 查询审核人ID集合
            List<AdmApplyRelation> relations = admApplyRelationMapper.selectList(
                Wrappers.<AdmApplyRelation>lambdaQuery().eq(AdmApplyRelation::getSealId, id)
            );
            if (relations != null && !relations.isEmpty()) {
                String principalIds = relations.stream()
                    .map(r -> String.valueOf(r.getPrincipalId()))
                    .distinct()
                    .reduce((a, b) -> a + "," + b)
                    .orElse("");
                entity.setPrincipalIds(principalIds);
            }

            // 查询文件列表
            List<AdmSealFile> files = admSealFileMapper.selectList(
                Wrappers.<AdmSealFile>lambdaQuery().eq(AdmSealFile::getSealId, id)
            );
            if (files != null && !files.isEmpty()) {
                List<AdmSealFileBo> fileBos = files.stream()
                    .map(this::convertToFileBo)
                    .toList();
                entity.setSealFiles(fileBos);
            }

            // 如果是审核VO，需要额外查询部门名称和用户名称
            if (entity instanceof AdmSealAuditVo) {
                AdmSealAuditVo auditVo = (AdmSealAuditVo) entity;
                // 查询部门名称
                if (seal.getDeptId() != null) {
                    var dept = deptService.selectDeptById(seal.getDeptId());
                    if (dept != null) {
                        auditVo.setDeptName(dept.getDeptName());
                    }
                }
                // 查询用户名称
                if (seal.getApplyId() != null) {
                    var user = userService.selectUserById(seal.getApplyId());
                    if (user != null) {
                        auditVo.setApplyName(user.getNickName());
                    }
                }
                // 设置董办审核意见
                auditVo.setApproverIdea(seal.getApproverIdea());
            }

            return entity;
        } catch (Exception e) {
            throw new RuntimeException("创建对象失败: " + targetClass.getSimpleName(), e);
        }
    }

    /**
     * AdmSealFile对象转AdmSealFileBo
     */
    private AdmSealFileBo convertToFileBo(AdmSealFile file) {
        AdmSealFileBo fileBo = new AdmSealFileBo();
        fileBo.setId(file.getId());
        fileBo.setFileName(file.getFileName());
        fileBo.setFileCount(file.getFileCount());
        fileBo.setSealId(file.getSealId());
        return fileBo;
    }
}
